const express = require("express");
const app = express();
const Vue = require("vue");
let path = require("path");
const vueServerRender = require("vue-server-renderer").createRenderer({
    template:require("fs").readFileSync(path.join(__dirname,"./index.html"),"utf-8")
});
app.get('*', (request, response) => {
    const vueApp = new Vue({
        data:{
           message: "hello, Vue SSR"
        },
        template: `<h1>{{message}}</h1>`
    });
    response.status(200);
    response.setHeader("Content-type", "text/html;charset-utf-8");
    vueServerRender.renderToString(vueApp).then((html) => {
        response.end(html);
    }).catch(err => console.log(err))
})
app.listen(3001, () => {
    console.log('服务已开启')
})


